--Check Class
if select(2, UnitClass('player')) ~= "PALADIN" then
    DisableAddOn("HolyPowerIndicator")
    return
end


--Remove Blizzard Frame
PaladinPowerBar:SetAlpha(0)


local locked = true;

--Frame
local frame, events = CreateFrame("Frame", "HPI", UIParent),{}
local texture = frame:CreateTexture()
frame:SetMovable()
frame:EnableMouse(false)
frame:SetPoint("CENTER",0, 0)
frame:SetWidth(115)
frame:SetHeight(115)
texture:SetAllPoints(frame)
frame:SetUserPlaced(true)

--Alpha
frame:SetAlpha(1)

--Scale
frame:SetScale(0.85)


--Designate Texture (change Alliance to desired texture folder, i.e. Horde, Coins, etc.)
local textureSelect = "Interface\\AddOns\\HolyPowerIndicator\\Number\\"


--Lock/Unlock Frame
function frame:toggleLock()
	if locked then
		locked = false
		frame:EnableMouse(true)
		frame:RegisterForDrag("LeftButton")
		frame:SetScript("OnDragStart", function(self) 
			self:StartMoving()
		end)
		frame:SetScript("OnDragStop", function(self)
			self:StopMovingOrSizing()
		end)
		texture:SetTexture(textureSelect.."3.tga")
                            frame:Show()
	else
		locked = true
		frame:EnableMouse(false)
		frame:RegisterForDrag(nil)
		frame:SetScript("OnDragStart", nil)
		frame:SetScript("OnDragStop", nil)
		frame:Hide()
	end
end


SLASH_HOLYPOWERINDICATOR1 = "/hpi";
SlashCmdList["HOLYPOWERINDICATOR"] = function(msg)
    if msg == "lock" then
        frame:toggleLock()
    end
end


--Find Holy Power & display count
function events:UNIT_POWER(source,type)
    if source == "player" and type == "HOLY_POWER" then
        local power = UnitPower("player",9)

        if power == 1 then
            texture:SetTexture(textureSelect.."1.tga")
            frame:Show()

        elseif power == 2 then
            texture:SetTexture(textureSelect.."2.tga")
            frame:Show()

        elseif power == 3 then
            texture:SetTexture(textureSelect.."3.tga")
            frame:Show()

        elseif power == 0 then
            frame:Hide()
        end
    end
end

--Register Events
frame:SetScript("OnEvent",function(self,event,...) events[event](self,...) end)

for k,v in pairs(events) do
    frame:RegisterEvent(k)
end